//
//  FunctionViewController.m
//  SelfDriving
//
//  Created by apple on 16/1/11.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "FunctionViewController.h"
#import "BusinessService+User.h"
@interface FunctionViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *table;

@end

@implementation FunctionViewController{
    int tixing_comment;
    int tixing_zan;
    int tixing_frienddynamic;
    int tixing_notfriendmsg;
    int tixing_group;

}
-(void)viewWillAppear:(BOOL)animated{
    [[AppDelegate shareDelegate]refdata:^(id res) {
        tixing_comment =  [[AppDelegate shareDelegate].user.tixing_comment intValue];
        tixing_zan =  [[AppDelegate shareDelegate].user.tixing_zan intValue];
        tixing_frienddynamic =  [[AppDelegate shareDelegate].user.tixing_frienddynamic intValue];
        tixing_notfriendmsg =  [[AppDelegate shareDelegate].user.tixing_notfriendmsg intValue];
        tixing_group =  [[AppDelegate shareDelegate].user.tixing_group intValue];
        [_table reloadData];
    }];

}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = NO;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//    return 2;
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 3;
    }
//    if (section == 1) {
//        return 2;
//    }
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return @"动态提醒";
    }
//    if (section == 1) {
//        return @"其他提醒";
//    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 120, 30)];
            title.text = @"评论提醒";
            title.font = [UIFont systemFontOfSize:14];
            [cell.contentView addSubview:title];
            
            UILabel *content = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 30)];
            content.text = @"有人评论，回复你动态提醒你";
            content.textColor = colorGrey;
            
            content.font = [UIFont systemFontOfSize:13];
            [cell.contentView addSubview:content];
            
            
            UISwitch *switchs = [[UISwitch alloc]initWithFrame:CGRectMake(SCRE_WIDTH-70, 20, 90, 30)];
            switchs.tag = 100;
            [switchs addTarget:self action:@selector(switchsAction:) forControlEvents:UIControlEventValueChanged];
            if (tixing_comment==0) {
                [switchs setOn:NO];
            }else{
                [switchs setOn:YES];
            }
            [cell.contentView addSubview:switchs];
        }
        if (indexPath.row == 1) {
            UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 120, 30)];
            title.text = @"点赞提醒";
            title.font = [UIFont systemFontOfSize:14];
            [cell.contentView addSubview:title];
            
            UILabel *content = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 30)];
            content.text = @"有人给你动态点赞时提醒你";
            content.textColor = colorGrey;
            
            content.font = [UIFont systemFontOfSize:13];
            [cell.contentView addSubview:content];
            
            UISwitch *switchs = [[UISwitch alloc]initWithFrame:CGRectMake(SCRE_WIDTH-70, 20, 90, 30)];
            switchs.tag = 101;
            [switchs addTarget:self action:@selector(switchsAction:) forControlEvents:UIControlEventValueChanged];
            if (tixing_zan==0) {
                [switchs setOn:NO];
            }else{
                [switchs setOn:YES];
            }
            [cell.contentView addSubview:switchs];
        }
        if (indexPath.row == 2) {
            UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 120, 30)];
            title.text = @"好友动态提醒";
            title.font = [UIFont systemFontOfSize:14];
            [cell.contentView addSubview:title];
            
            UILabel *content = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 30)];
            content.text = @"好友发动态时提醒你";
            content.textColor = colorGrey;
            
            content.font = [UIFont systemFontOfSize:13];
            [cell.contentView addSubview:content];
            
            UISwitch *switchs = [[UISwitch alloc]initWithFrame:CGRectMake(SCRE_WIDTH-70, 20, 90, 30)];
            switchs.tag = 102;
            [switchs addTarget:self action:@selector(switchsAction:) forControlEvents:UIControlEventValueChanged];
            if (tixing_frienddynamic==0) {
                [switchs setOn:NO];
            }else{
                [switchs setOn:YES];
            }
            [cell.contentView addSubview:switchs];
        }
        
    }
    if(indexPath.section == 1){
        if (indexPath.row == 0) {
            UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 120, 30)];
            title.text = @"陌生人消息提醒";
            title.font = [UIFont systemFontOfSize:14];
            [cell.contentView addSubview:title];
            
            UILabel *content = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 30)];
            content.text = @"陌生人想你打招呼时提醒你";
            content.textColor = colorGrey;
            content.font = [UIFont systemFontOfSize:13];
            [cell.contentView addSubview:content];
            
            UISwitch *switchs = [[UISwitch alloc]initWithFrame:CGRectMake(SCRE_WIDTH-70, 20, 90, 30)];
            switchs.tag = 103;
            [switchs addTarget:self action:@selector(switchsAction:) forControlEvents:UIControlEventValueChanged];
            if (tixing_notfriendmsg==0) {
                [switchs setOn:NO];
            }else{
                [switchs setOn:YES];
            }
            [cell.contentView addSubview:switchs];
        }
        if (indexPath.row == 1) {
            UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 120, 30)];
            title.text = @"群组提醒";
            title.font = [UIFont systemFontOfSize:14];
            [cell.contentView addSubview:title];
            
            UILabel *content = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, 200, 30)];
            content.text = @"好友加群，有加群申请时提醒你";
            content.font = [UIFont systemFontOfSize:13];
            content.textColor = colorGrey;
            [cell.contentView addSubview:content];
            
            UISwitch *switchs = [[UISwitch alloc]initWithFrame:CGRectMake(SCRE_WIDTH-70, 20, 90, 30)];
            switchs.tag = 104;
            [switchs addTarget:self action:@selector(switchsAction:) forControlEvents:UIControlEventValueChanged];
            if (tixing_group==0) {
                [switchs setOn:NO];
            }else{
                [switchs setOn:YES];
            }
            [cell.contentView addSubview:switchs];
        }
    }
    return cell;
}
#pragma mark 设置消息提示
-(void)switchsAction:(UISwitch *)sw{
    if(sw.tag == 100){//评论
        if (!sw.on) {
            tixing_comment = 0;
        }else{
            tixing_comment = 1;
        }
    }
    if(sw.tag == 101){//点赞
        if (!sw.on) {
            tixing_zan = 0;
        }else{
            tixing_zan = 1;
        }
    }
    if(sw.tag == 102){//好友动态
        if (!sw.on) {
            tixing_frienddynamic = 0;
        }else{
            tixing_frienddynamic = 1;
        }
    }
    if(sw.tag == 103){//陌生人
        if (!sw.on) {
            tixing_notfriendmsg = 0;
        }else{
            tixing_notfriendmsg = 1;
        }
    }
    if(sw.tag == 104){//群组
        if (!sw.on) {
            tixing_group = 0;
        }else{
            tixing_group = 1;
        }
    }
     NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[NSNumber numberWithInt:tixing_comment] forKey:@"tixing_comment"];
    [dic setObject:[NSNumber numberWithInt:tixing_zan] forKey:@"tixing_zan"];
    [dic setObject:[NSNumber numberWithInt:tixing_frienddynamic] forKey:@"tixing_frienddynamic"];
//    [dic setObject:[NSNumber numberWithInt:tixing_notfriendmsg] forKey:@"tixing_notfriendmsg"];
//    [dic setObject:[NSNumber numberWithInt:tixing_group] forKey:@"tixing_group"];
    [[BusinessService shareInstance]setUserOtherConfig:dic success:^(id result) {
        [SVProgressHUD showSuccessWithStatus:@"设置成功"];
        [_table reloadData];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            
        }
        if (indexPath.row == 1) {
            
            
            
        }
    }
    
}





- (IBAction)backActino:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


@end
